<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property int $admin_id 
 * @property int $user_id 
 * @property int $recharge_rmb 
 * @property int $total_recharge_rmb 
 * @property int $flag 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 */
class UsersRechargeLimit extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'users_recharge_limit';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'admin_id' => 'integer', 'user_id' => 'integer', 'recharge_rmb' => 'integer', 'total_recharge_rmb' => 'integer', 'flag' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    /**
     * 获用户限制金额
     * @param int $user_id
     * @return array|int[]
     */
    public static function getByUidLimit($user_id=0)
    {
        $ret = [
            'recharge_rmb' => 0,
            'total_recharge_rmb'=>0
        ];
        if(!$user_id) return $ret;
        $limitInfo = self::where('user_id',$user_id)->where('flag',1)->first();
        return [
            'recharge_rmb' => empty($limitInfo['recharge_rmb']) ? 0 : $limitInfo['recharge_rmb'],
            'total_recharge_rmb' => empty($limitInfo['total_recharge_rmb']) ? 0 : $limitInfo['total_recharge_rmb']
        ];
    }
}